<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb>
      <el-breadcrumb-item to="/dashboard">首页</el-breadcrumb-item>
      <el-breadcrumb-item>分类管理</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card class="user-container">
      <!-- 按钮组 -->
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="webgis" name="webgis">
          <el-table :data="categorys" stripe border>
            <el-table-column label="序号" prop="index"></el-table-column>
            <el-table-column label="id" prop="id"></el-table-column>
            <el-table-column
              label="分类名称"
              prop="category_name"
            ></el-table-column>
            <el-table-column label="标题" prop="title"></el-table-column>
            <el-table-column label="操作">
              <template v-slot="scoped">
                <el-button
                  id="id"
                  type="primary"
                  size="mini"
                  icon="el-icon-edit"
                  @click="handleEdit(scoped.row.id)"
                  >编辑</el-button
                >
                <el-button type="danger" size="mini" icon="el-icon-delete"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="倾斜摄影" name="倾斜摄影">
          <el-table :data="categorys" stripe border>
            <!-- 添加序号列 -->
            <el-table-column label="序号" prop="index"></el-table-column>
            <el-table-column label="id" prop="id"></el-table-column>
            <el-table-column
              label="分类名称"
              prop="category_name"
            ></el-table-column>
            <el-table-column label="标题" prop="title"></el-table-column>
            <el-table-column label="操作">
              <template v-slot="scoped">
                <el-button
                  id="id"
                  type="primary"
                  size="mini"
                  icon="el-icon-edit"
                  @click="handleEdit(scoped.row.id)"
                  >编辑</el-button
                >
                <el-button type="danger" size="mini" icon="el-icon-delete"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="数据处理" name="数据处理">
          <el-table :data="categorys" stripe border>
            <el-table-column label="序号" prop="index"></el-table-column>
            <el-table-column label="id" prop="id"></el-table-column>
            <el-table-column
              label="分类名称"
              prop="category_name"
            ></el-table-column>
            <el-table-column label="标题" prop="title"></el-table-column>
            <el-table-column label="操作">
              <template v-slot="scoped">
                <el-button
                  id="id"
                  type="primary"
                  size="mini"
                  icon="el-icon-edit"
                  @click="handleEdit(scoped.row.id)"
                  >编辑</el-button
                >
                <el-button type="danger" size="mini" icon="el-icon-delete"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>

      <!-- 数据表格 -->
      <!-- <el-table :data="categorys" stripe border>
        <el-table-column label="id" prop="id"></el-table-column>
        <el-table-column
          label="分类名称"
          prop="category_name"
        ></el-table-column>
        <el-table-column label="标题" prop="title"></el-table-column>
        <el-table-column label="操作">
           <template v-slot="scoped">
             <el-button
              type="primary"
              size="mini"
              icon="el-icon-edit"
              @click="handleEdit(scoped.row)"
              >编辑</el-button
            >
            <el-button type="danger" size="mini" icon="el-icon-delete"
              >删除</el-button
            > 
          </template> 
        </el-table-column>
      </el-table> -->
      <!-- 分页器 -->
      <!--  -->
      <!-- <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="[1, 2, 3, 5]"
        :page-size="size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination> -->
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Category',
  data() {
    return {
      keywords: '',
      categorys: [
        // { id: 1, category: 'webgis', title: '11111' },
        // { id: 2, category: 'webgis', title: '11111' },
        // { id: 3, category: 'webgis', title: '11111' },
      ],
      activeName: 'webgis', //初始界面
    };
  },

  //创建生命周期, 定义created生命周期函数, 完成data数据的初始化
  created() {
    this.getCategory('webgis'); //初始界面传参
  },
  //方法,发送请求,获取blogs列表
  methods: {
    getCategory(name) {
      this.$http.get('/blogs').then((res) => {
        //console.log(res);
        const arr = [];
        let index = 1; //分类 序号初始化
        for (let i = 0; i < res.result.length; i++) {
          if (res.result[i].category_name == name) {
            res.result[i].index = index; //在数据中添加index 序号键值对,显示排序正常
            console.log();
            index++;
            arr.push(res.result[i]);
            // console.log(arr);
          }
        }

        this.categorys = arr;
      });
    },
    handleClick(tab, event) {
      console.log(tab, event);
      console.log(tab.name);
      this.getCategory(tab.name);
    },

    handleEdit(id) {
      // console.log(row);
      this.$router.push({
        path: `/update?id=${id}`,
      });

      // <el-menu-item index="/post">
      //   <i class="el-icon-document"></i>
      //   <span slot="title">新增博客</span>
      // </el-menu-item>;
      //显示对话框
      // this.dialogVisible = true;
      // this.isEdit = true;
      //回显数据
      // this.$http.get(`/users/${row.id}`).then((data) => {
      //   this.form = data.result;
      // });
    },
  },
};
</script>

<style scoped>
/* scoped:(作用域)在这里写的样式仅仅会影响当前组件 */
.user-container {
  margin-top: 20px;
  /* height: 400px; */
}
.el-table {
  margin-top: 0px;
}
</style>
